#pragma once
#include <stdio.h>
#include <atlstr.h>
#include <comsvcs.h>
#include <vidcap.h>
#include <windows.h>
#include <ksproxy.h>
#include <strmif.h>
#include <dshow.h>
#include <ks.h>
#include <ksmedia.h>
#include <comutil.h>
#include <string>

#define MAX_CAM_NUM 10
#define MAX_EX_UNIT_NUM 10
#define MAX_CAM_NAME_LEN 1000

namespace CameraAI
{

	typedef struct {
		unsigned long  Data1;
		unsigned short Data2;
		unsigned short Data3;
		unsigned char  Data4[8];
	}UsbGuid;

	typedef enum {
		QUERY_SET = 0,
		QUERY_GET = 1,
	}QueryType;

	typedef struct {
		//windows枚举的扩展单元id
		unsigned char KsNodeID;
		//扩展命令cs
		unsigned char CtrlID;
		//get或者set
		QueryType query;
		//数据buf，需要主动传入
		unsigned char* data;
		//命令长度
		unsigned short len;
		//扩展单元guid
		UsbGuid guid;
	}ExCtrlCmd;

	typedef struct {
		int UnitID;//描述符中扩展单元id,目前未实现自动获取，这个可以不用填
		int KsNodeID;//windows枚举的扩展单元id
		UsbGuid guid;//扩展单元guid，目前未实现自动获取，需要手动从扩展单元描述符中获取
	}ExUnitInfo;

	typedef struct {
		//设备显示名字
		char name[64];
		unsigned short vid;
		unsigned short pid;
		char devPath[MAX_CAM_NAME_LEN];
	}CamDevInfo;

	class CameraHelper
	{
//要查找的设备vid
#define DEV_VID 0x2bdf
#define DEV_PID 0x060a
#define USB_CAM_LIB_FAIL -1
#define USB_CAM_LIB_OK 0
#define USB_CAM_LIB_SUCCESS 0
		public:

			CameraHelper()
			{
				InitUsbCamLib();
			}

			~CameraHelper()
			{
				UnInitUsbCamLib();
			}

			int EnumDevice();

			int GetDeviceSatus(const char* devPath);

			bool SetDeviceSatus(const char* devPath, int index);

			bool SetMirror(const char* devPath, bool isMirror);

			/// <summary>
			/// 目前只支持两种-将来未必所以参数用int
			/// </summary>
			/// <param name="index">0 中文cn, 1 英文en</param>
			/// <returns></returns>
			bool SetLanguage(const char* devPath, int index);

		private:
			IBaseFilter* piFilter;
			/*ExUnitInfo euInfos[7];*/
			void InitUsbCamLib();
			void UnInitUsbCamLib();
			int openCameraDevice(const char* devPath);
			int UvcXuCommand(ExCtrlCmd* cmd);
			int eu2_set(int cs, unsigned char* data, int len);
			int eu2_get(int cs, unsigned char* buf);
			int GetCurCamDevs(CamDevInfo(*devInfo)[MAX_CAM_NUM], int* hasFindDevNum);
			int GetIKsControl(IBaseFilter* pCaptureFilter, IKsControl** ppKsControl);
			UsbGuid xuGUID = { 0x2C49D16A, 0x32B8, 0x4485,{ 0x3E, 0xA8, 0x64, 0x3A, 0x15, 0x23, 0x62, 0xF2} };

	};

	

}

